package com.google.code.p.narcissus.core.model;

import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Pojo aimed at encapsulating all reference meta data information.
 * 
 * @author Jérôme JADOULLE [JADOJ] - 3 août 2010
 */
public class ReferenceMetaData {

	private Date creationDate;

	private Date lastUpdateDate;

	private String comment;

	private List<Rectangle> exclusionZones;
	
	public ReferenceMetaData(List<Rectangle> exclusionZones) {
		this(exclusionZones, null);
	}

	public ReferenceMetaData(List<Rectangle> exclusionZones, String comment) {
		super();
		this.exclusionZones = exclusionZones;
		creationDate = new Date();
		lastUpdateDate = new Date();
		this.comment = comment;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
		lastUpdateDate = new Date();
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
		lastUpdateDate = new Date();
	}

	public List<Rectangle> getExclusionZones() {
		return exclusionZones == null ? new ArrayList<Rectangle>() : exclusionZones;
	}

	public void setExclusionZones(List<Rectangle> exclusionZones) {
		this.exclusionZones = exclusionZones;
		lastUpdateDate = new Date();
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public Date getLastUpdateDate() {
		return lastUpdateDate;
	}

	/**
	 * Tells whether the pixel whose coordinates are passed in parameter is in an exclusion zone or not.
	 * 
	 * @param x
	 * @param y
	 * @return true if the pixel is in an exclusion zone, false if not.
	 */
	public boolean isAnExclusionZonePixel(int x, int y) {
		if (exclusionZones != null) {
			for (Rectangle currentZone : exclusionZones) {
				if (x >= currentZone.x && x <= (currentZone.width + currentZone.x) && y >= currentZone.y && y <= (currentZone.height + currentZone.y)) {
					return true;
				}
			}
		}

		return false;
	}

}
